<?php
require_once './data/users.php';
?>
<form method="POST">
    <table>
        <tr><td>Username <input type="text" name="username"></tr></td>
        <tr><td>Pass     <input type="password" name="password"></tr></td>
        <tr><td>         <input type="submit" name="submit"></tr></td>
    </table>
</form>
<?php if (isset($_POST['submit'])): ?>
    <?php
    $username = $_POST['username'];
    $password = $_POST['password'];
    $isOk = FALSE;
    $index = -1;
    for ($i = 0; $i < count($users); $i++) {
        if ((strcmp($users[$i]['username'], $username) == 0) &&
                (strcmp($users[$i]['password'], $password) == 0)) {
            $isOk = TRUE;
            $index = $i;
        }
    }
    if ($isOk) {
        header("Location: http://localhost:82/huaduy-web1/flim.php?uid=" . $users[$index]['id']);
    } else {
        echo 'Erro';
    }
    ?>
<?php endif; ?>

